#!/bin/bash


theoretical 

echo $1 $2 $3

TEMP=`getopt -o ymd --long from-year,from-month,from-day`

# Note the quotes around `$TEMP': they are essential!
echo "$TEMP"

eval set -- "$TEMP"

echo $TEMP

fromyear=2003
frommonth=01
fromday=01


echo "a $0, $1, $2"
while true ; do
    case "$1" in
        -y|--from-year) 
                echo "$1 " ; shift; echo $1 $2;
                ;;
        -m|--from-month) 
            echo "Option m, argument \`$2'" ; echo "$1,$2"; shift 2 ;;
        -d|--from-day)

           case "$2" in
                "") 
                echo "Option d, no argument"; shift 2 ;;
                 *) 
                echo "Option d, argument \`$2'" ; shift 2 ;;
           esac ;;

        --) 
            shift ; break ;;
        *) 
            echo "Internal error!" ; exit 1 ;;
    esac
done

exit

getopt -l fromyear

if `getopt -T >/dev/null 2>&1` ; [ $? = 4 ] ; then
  echo "Enhanced getopt(1)"
else
  echo "Old getopt(1)"
fi


list = nyselist.txt

if [ -n "$1" ]
	$list = $1
fi

today=`date`
curyear=`date +%Y`
curday=`date +%d`
curmonth=`date +%m`

if [ -n "$2" ] ; then
	fromyear=2001
fi
if [ -n "$3" ] ; then
	fromday=02
fi

frommonth=

echo $year,$month,$day

for i in `cat $list |awk '{printf $1"\n" }'`; do
  echo $i " dog";
  wget -O ./data/$i.csv  "http://ichart.finance.yahoo.com/table.csv?s=$i&a=01&b=6&c=2001&d=02&e=24&f=2011&g=d&ignore=.csv"
done
